package com.lijinjiang.graphics;

import javax.swing.*;
import java.awt.*;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Rectangle2D;

/**
 * @Description 确认图标
 * @Author lijinjiang
 * @Date 2024-12-30 10:52
 */
public class JCalendarIcon implements Icon {
    private int width;
    private int height;

    public JCalendarIcon(int width, int height) {
        setDimension(width, height);
    }

    public void setDimension(int width, int height) {
        this.width = width;
        this.height = height;
    }

    @Override
    public void paintIcon(Component c, Graphics g, int x, int y) {
        Graphics2D g2d = (Graphics2D) g;

        //设置抗锯齿
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

        //设置线条颜色和粗细
        g2d.setColor(Color.BLACK);
        g2d.setStroke(new BasicStroke(1.6F));

        double l = (double) width * 3 / 8;//时钟的直径

        //绘制日历部分
        Rectangle2D calendar = new Rectangle2D.Double(4, 6, width - 10, 6);
        g2d.draw(calendar);
        //绘制日历上俩挂钩
        g2d.drawLine((width - 10) / 3 + 4, 4, (width - 10) / 3 + 4, 8);
        g2d.drawLine(width - (width - 10) / 3 - 6, 4, width - (width - 10) / 3 - 6, 8);

        //绘制左下角边框
        g2d.drawLine(4, 12, 4, height - 6);
        g2d.drawLine(4, height - 6, 10 * (width - 10) / 21 + 4, height - 6);

        //绘制俩横
        g2d.drawLine(7, 6 + height / 3, 7 + 5 * (width - 10) / 21, 6 + height / 3);
        g2d.drawLine(7, 2 * height / 3, 7 + 5 * (width - 10) / 21, 2 * height / 3);

        //绘制时钟部分
        Ellipse2D clock = new Ellipse2D.Double(width - 4 - l, height - 4 - l, l, l);
        g2d.draw(clock);
        //绘制指针
        g2d.drawLine((int) (width - 4 - l / 2), (int) (height - 4 - 3 * l / 4), (int) (width - 4 - l / 2), (int) (height - 4 - l / 2));
        g2d.drawLine((int) (width - 4 - l / 2), (int) (height - 4 - l / 2), (int) (width - 4 - l / 6), (int) (height - 4 - l / 2));

    }

    @Override
    public int getIconWidth() {
        return width;
    }

    @Override
    public int getIconHeight() {
        return height;
    }
}
